/**
 */
package de.thwildau.tm.moses.xabnf.xabnf.impl;

import de.thwildau.tm.moses.xabnf.xabnf.FieldBinding;
import de.thwildau.tm.moses.xabnf.xabnf.RuleBinding;
import de.thwildau.tm.moses.xabnf.xabnf.XabnfPackage;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Rule Binding</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link de.thwildau.tm.moses.xabnf.xabnf.impl.RuleBindingImpl#getTargetRuleName <em>Target Rule Name</em>}</li>
 *   <li>{@link de.thwildau.tm.moses.xabnf.xabnf.impl.RuleBindingImpl#getFieldBindings <em>Field Bindings</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RuleBindingImpl extends BindingImpl implements RuleBinding
{
  /**
   * The default value of the '{@link #getTargetRuleName() <em>Target Rule Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getTargetRuleName()
   * @generated
   * @ordered
   */
  protected static final String TARGET_RULE_NAME_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getTargetRuleName() <em>Target Rule Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getTargetRuleName()
   * @generated
   * @ordered
   */
  protected String targetRuleName = TARGET_RULE_NAME_EDEFAULT;

  /**
   * The cached value of the '{@link #getFieldBindings() <em>Field Bindings</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getFieldBindings()
   * @generated
   * @ordered
   */
  protected EList<FieldBinding> fieldBindings;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected RuleBindingImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return XabnfPackage.Literals.RULE_BINDING;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getTargetRuleName()
  {
    return targetRuleName;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setTargetRuleName(String newTargetRuleName)
  {
    String oldTargetRuleName = targetRuleName;
    targetRuleName = newTargetRuleName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, XabnfPackage.RULE_BINDING__TARGET_RULE_NAME, oldTargetRuleName, targetRuleName));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<FieldBinding> getFieldBindings()
  {
    if (fieldBindings == null)
    {
      fieldBindings = new EObjectContainmentEList<FieldBinding>(FieldBinding.class, this, XabnfPackage.RULE_BINDING__FIELD_BINDINGS);
    }
    return fieldBindings;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case XabnfPackage.RULE_BINDING__FIELD_BINDINGS:
        return ((InternalEList<?>)getFieldBindings()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case XabnfPackage.RULE_BINDING__TARGET_RULE_NAME:
        return getTargetRuleName();
      case XabnfPackage.RULE_BINDING__FIELD_BINDINGS:
        return getFieldBindings();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case XabnfPackage.RULE_BINDING__TARGET_RULE_NAME:
        setTargetRuleName((String)newValue);
        return;
      case XabnfPackage.RULE_BINDING__FIELD_BINDINGS:
        getFieldBindings().clear();
        getFieldBindings().addAll((Collection<? extends FieldBinding>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case XabnfPackage.RULE_BINDING__TARGET_RULE_NAME:
        setTargetRuleName(TARGET_RULE_NAME_EDEFAULT);
        return;
      case XabnfPackage.RULE_BINDING__FIELD_BINDINGS:
        getFieldBindings().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case XabnfPackage.RULE_BINDING__TARGET_RULE_NAME:
        return TARGET_RULE_NAME_EDEFAULT == null ? targetRuleName != null : !TARGET_RULE_NAME_EDEFAULT.equals(targetRuleName);
      case XabnfPackage.RULE_BINDING__FIELD_BINDINGS:
        return fieldBindings != null && !fieldBindings.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (targetRuleName: ");
    result.append(targetRuleName);
    result.append(')');
    return result.toString();
  }

} //RuleBindingImpl
